// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    dianh: '',
    sjbug: false,
    yanzmq: '获取验证码',
    qued: true,
    suiji:'',
    ya:null,
  },
  yanz() {
    this.sjihaoyan();
    if(!this.data.sjbug){
      this.daojis();
    }
  },
  sjihaoyan(){
    let ze = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
    if (ze.test(this.data.dianh)) {
      this.setData({
        sjbug: false
      })
    } else {
      this.setData({
        sjbug: true
      })
      // this.daojis();
    }
  },
  shoji(e) {
    this.data.dianh = e.detail.value
  },
  daojis() {
    let daojis = 5;
    let qued = this.data.qued;
    let creal;
    if (qued) {
      this.setData({
        qued: false
      })
      this.yanzma()
      creal = setInterval(() => {
        daojis--
        this.setData({
          yanzmq: daojis
        })
        if(daojis <= 0){
          this.setData({
           yanzmq:'重新获取',
           qued:true
          })
          clearInterval(creal)
       }
      }, 1000)
    }
  },
  yanzma() {
    this.setData({
      suiji:parseInt( Math.random()*10000)
    })
  },
  tij(e){
     this.setData({
      ya:e.detail.value
     })
  },
  login(){
   
    this.sjihaoyan();
    if(!this.data.sjbug){
      this.tiapz()
    }
  },
  tiapz(){
    if(this.data.ya == this.data.suiji){
      wx.navigateTo({
        url: "/pages/log/log"
      })
    }else{
      console.log('验证码错误')
    }
  },
  onLoad() {

  },


})
